﻿using TiaoTiaoCode.Common.Enums;

namespace TiaoTiaoCode.Modbuser.Interfaces
{
    /// <summary>
    /// ModbusTcp对象接口
    /// </summary>
    public interface ITcpModbuser : IModbuser
    {      
        /// <summary>
        /// 设置连接
        /// </summary>
        /// <param name="ip">连接IP</param>
        /// <param name="port">连接端口</param>
        /// <returns></returns>
        ITcpModbuser SetConnectInfo(string ip = "127.0.0.1", ushort port = 502);

        /// <summary>
        /// 设置站号
        /// </summary>
        /// <param name="station"></param>
        /// <returns></returns>
        ITcpModbuser SetStation(byte station);

        /// <summary>
        /// 设置字节流顺序
        /// </summary>
        /// <param name="dataFormat"></param>
        /// <returns></returns>
        ITcpModbuser SetByteDataFormat(ByteDataFormatType dataFormat);

        /// <summary>
        /// 设置是否首地址为0
        /// </summary>
        /// <param name="addressStartWithZero"></param>
        /// <returns></returns>
        ITcpModbuser SetAddressStartWithZero(bool addressStartWithZero);

        /// <summary>
        /// 设置字符串是否反转
        /// </summary>
        /// <param name="isStringReverse"></param>
        /// <returns></returns>
        ITcpModbuser SetIsStringReverse(bool isStringReverse);

        /// <summary>
        /// 设置是否检查消息号一致
        /// </summary>
        /// <param name="checkMessageId"></param>
        /// <returns></returns>
        ITcpModbuser SetCheckMessageId(bool checkMessageId);

        /// <summary>
        /// 读取连续的数据内容
        /// </summary>
        /// <typeparam name="T">限定只能是基础数据类型</typeparam>
        /// <param name="startAddress">开始读取的地址位</param>
        /// <param name="readLength">读取长度</param>
        /// <returns></returns>
        T[] Read<T>(string startAddress, ushort readLength);
    }
}
